package com.yidu.view;

import java.io.IOException;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.yidu.commom.Tool;
import com.yidu.message.Message;
import com.yidu.service.TbImageService;

/**
 * 类的描述-- 图片类 action
 * @author 楠竹
 * @date 2018年7月16日
 * @version 1.0
 */
@Controller
@RequestMapping("/image")
public class TbImageAction {

	//输出打印控制台
	Logger logger  = Logger.getLogger(TbImageAction.class);

	//json
	ObjectMapper mapper = new ObjectMapper();

	//消息信息类
	Message msg = new Message();

	@Resource
	private TbImageService imageService;


	@RequestMapping("/getFileName")
	@ResponseBody
	private Object getFileName(HttpServletRequest request) throws IOException{
		logger.info("图片处理..");
		//得到文件
		MultipartHttpServletRequest mreq = (MultipartHttpServletRequest)request; 

		MultipartFile file = mreq.getFile("file");

		//得到文件名 
		String fileName=null;
		if(!file.isEmpty() && file.getSize()>0 ){
			fileName = Tool.output(file, request); 
			logger.info(fileName); 
			msg.setNum(1);
		}else{
			msg.setNum(0);
			logger.info("失败...");
		}
		msg.setMsg(fileName); 
		return msg;


	}

}
